﻿using System.Collections.Generic;
using System.Linq;
using eCommerce.db.DALRespository;
using eCommerce.db.DataRespository;
using eCommerce.db.SQLDataAccess;

namespace eCommerce.db.BORespository
{
    public class IeDetailBo
    {
        public static List<IeDetailEntity> ListDistinctProductByIeId(long ieId)
        {
            return IeDetailDal.ListDistinctProductByIeId(ieId);
        }

        public static List<IeDetailEntity> ListSizeAndQuantityByProduct(long ieId, int productId)
        {
            return IeDetailDal.ListSizeAndQuantityByProduct(ieId, productId);
        }

        public static string SizeAndQuantityByProduct(long ieId, int productId)
        {
            var strReturn = string.Empty;
            var lstIeDetail = ListSizeAndQuantityByProduct(ieId, productId);
            if (lstIeDetail != null && lstIeDetail.Count > 0)
                strReturn = lstIeDetail.Aggregate(strReturn, (current, t) => current + string.Format("{0} (<strong class='cRed'>{1}</strong>), ", t.SizeName, t.Quantity));
            strReturn = !string.IsNullOrEmpty(strReturn) ? strReturn.Substring(0, strReturn.Length - 2) : strReturn;
            return strReturn;
        }

        public static void Create(IeDetailEntity o)
        {
            IeDetailDal.Create(o);
        }

        public static void Delete(long ieId, int productId)
        {
            IeDetailDal.Delete(ieId, productId);
        }

        public static void DeleteByIeId(int ieId)
        {
            IeDetailDal.DeleteByIeId(ieId);
        }
    }
}
